package com.atguigu.gmall.order.api;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.util.AuthContextHolder;
import com.atguigu.gmall.order.model.OrderInfo;
import com.atguigu.gmall.order.service.OrderInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * title:
 * author: Gyh
 * date:2023-05-07 14:16
 * Description:
 */
@RestController
@RequestMapping("/api/order")
public class OrderApiController {

    @Autowired
    private OrderInfoService orderInfoService;

    /**
     * 渲染用户订单确认页面相关参数
     * @param request
     * @return
     */
    @GetMapping("/auth/trade")
    public Result<Map> tradeDatas(HttpServletRequest request) {
        String userId = AuthContextHolder.getUserId(request);
        //调用业务层封装相关数据
        Map<String, Object> mapData = orderInfoService.tradeDatas(Long.valueOf(userId));
        return Result.ok(mapData);
    }

    /**
     * 根据订单Id查询订单信息,包括订单的明细
     * @param orderId
     * @return
     */
    @GetMapping("/inner/getOrderInfo/{orderId}")
    public OrderInfo getOrderInfoById(@PathVariable("orderId") Long orderId){
        return orderInfoService.getOrderInfoById(orderId);
    }

    /**
     * 提供给库存系统调用订单拆单接口
     * @param orderId 订单ID
     * @param wareSkuMap [{"wareId":"1","skuIds":["28","29"]},{"wareId":"2","skuIds":["24"]}]
     * @return
     */
    @PostMapping("/orderSplit")
    public String orderSplit(String orderId,String wareSkuMap){
        return orderInfoService.orderSplit(orderId,wareSkuMap);
    }
}
